<?php
	require_once 'models/models_cthoadon.php';
	$mod = $_GET['mod'];
	$obCTHD = new models_cthoadon();
	require 'models/models_mathang.php';
	$obMH = new models_mathang();
	require_once 'models/models_hoadon.php';
	$obHD = new models_hoadon();
	switch ($mod){
		case 'cthoadon':{
			$data['list'] = $obCTHD->_listCTHoaDon();
			$data['listmh'] = $obMH->listMatHang();
			$data['listhd'] = $obHD->_listHoaDonn();
			require 'views/admin/cthoadon/index.php';
			break;
		}
		case 'add_cthoadon':{
			if($_POST){
				$obCTHD->_addCTHoaHon($_POST['cmb_MatHang'], $_POST['cmb_HoaDon'], $_POST['SoLuong'], $_POST['DonGia']);
				echo '<script>window.location.href="admin.php?mod=cthoadon"</script>';
			}
			$data['listhd'] = $obHD->_listHoaDonn();
			$data['listmh'] = $obMH->listMatHang();
			require 'views/admin/cthoadon/add.php';
			break;
		}
		case 'del_cthoadon':{
			$obCTHD->_delCTHoaDon($_GET['id']);
			echo '<script>window.location.href="admin.php?mod=cthoadon"</script>';
			break;
		}
		case 'edit_cthoadon':{
			if($_POST){
				$obCTHD->_editCTHoaDon($_POST['cmb_MatHang'], $_POST['cmb_HoaDon'], $_POST['SoLuong'], $_POST['DonGia'],$_GET['id']);
				echo '<script>window.location.href="admin.php?mod=cthoadon"</script>';
			}
			$data = $obCTHD->_getCTHoaDon($_GET['id']);
			$data['listhd'] = $obHD->_listHoaDonn();
			$data['listmh'] = $obMH->listMatHang();
			require 'views/admin/cthoadon/edit.php';
		}
	}
?>